home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97b.txt
/
000093_icon-group-sender _Fri Oct 24 08:39:27 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id IAA26548
for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Fri, 24 Oct 1997 08:39:26 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA24457; Fri, 24 Oct 1997 08:39:25 -0700
To: icon-group@cs.arizona.edu
Date: 24 Oct 1997 03:16:42 GMT
From: espie@litp.ibp.fr (Marc ESPIE)
Message-Id: <62p3uq$sup$1@vishnu.jussieu.fr>
Organization: LIAFA, Paris
Sender: icon-group-request@cs.arizona.edu
References: <Stuart.Robinson-2410970146220001@asianstmg-229.anu.edu.au>, <Stuart.Robinson-2410971258070001@asianstmg-229.anu.edu.au>
Reply-To: espie@litp.ibp.fr
Subject: Re: tabulating values
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
In article <Stuart.Robinson-2410971258070001@asianstmg-229.anu.edu.au>,
Stuart Robinson <Stuart.Robinson@anu.edu.au> wrote:
>Well, I've now received six responses to my query, none of which provide a
>solution to the problem. I really do appreciate the responses, but four
>of the responses consisted of people essentially saying "Heck, that's
>trivial" without proving it by actually providing a working solution and
>the two responses that did actually contain code failed to provide a
>solution. Here they are:
This problem is trivial... I'm sorry for you, I wish that people would
at least check what they're writing before answering.
>PROGRAM #1
>----------
>procedure main()
>
>t := table(0)
>while t[!read()] +:= 1
this is the erroneous line.
while t[read()] +:= 1
would be mostly correct.
The !read() does what it should on a string, namely take every character
one at a time.
However, this won't truely work for numerical values, as it distinguishes
010
from
10...
Try:
while t[integer(read())] +:= 1
which will convert explicitly the line read to integer.
Second catch: this one will fail as soon as you encounter a line that does
not hold an integer number. I would write
while n := read() do
t[integer(n)] +:= 1
that way, I can add an error condition whenever integer() fails, and
separate it from the stop condition of the main loop.
>write("value n")
>every i := !sort(t) do write(left(i[1], 9), left(i[2], 4))
>end
>PROGRAM #2
>----------
>procedure main()
>
>count := table(0)
>every n := read() do
>count[n] +:= 1
>
>write("value\tn")
>every n := key(count) do
>write(n, "\t", count[n])
This one should check what key() actually returns... which is a list.
It does suffer from the same `string is not an integer as program #1'.
Come on guys, when somebody asks a rather simple question, giving him
an half-baked program that doesn't work won't probably give him a clue
about what's wrong.
Stuart: I'm curious about the way you're using Icon. If you're truely
stuck with the program library as far as programming goes, you're only
using a small part of Icon. How about trying to learn and program ?
--
Marc Espie (espie@litp.ibp.fr)